package com.yenlien.traceyun.plant.controller;

import com.yenlien.traceyun.plant.entity.ColdStorageComp;
import com.yenlien.traceyun.plant.service.ColdStorageCompService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date 2022/8/30
 * @Author jiaLong
 * @Descript
 */
@RestController
@RequestMapping("/comp")
public class ColdStorageCompController extends BaseController {

    @Autowired
    private ColdStorageCompService coldStorageCompService;


    // 未登录时首页
    @GetMapping(value = "/findAllList")
    public Object findAllList(String lng, String lat) {
        return success(coldStorageCompService.findComp(lng, lat));
    }




    @PostMapping(value = "/save")
    public Object save(@RequestBody ColdStorageComp coldStorageComp)  {
        return success(coldStorageCompService.save(coldStorageComp));
    }

    @PostMapping(value = "/findByList")
    public Object findByList(@RequestBody ColdStorageComp coldStorageComp) {
        return success(coldStorageCompService.findByList(coldStorageComp));
    }

    @GetMapping(value = "/findById/{id}")
    public Object findById(@PathVariable("id") String id) {
        return success(coldStorageCompService.findById(id));
    }

    @GetMapping(value = "/findAll")
    public Object findAll() {
        return success(coldStorageCompService.findAll());
    }

    @GetMapping(value = "/findByState")
    public Object findByStateAndId(String state) {
        return success(coldStorageCompService.findByStateAndId(state));
    }


//    @PostMapping(value = "/export")
//    public void findByStateAndId(@RequestBody ColdStorageComp coldStorageComp, HttpServletResponse response) {
//        List<ColdStorageComp> coldStorageCompList = coldStorageCompService.export(coldStorageComp);
//        try {
//            response.setHeader("Content-disposition", "attachment;filename=" + "冷链企业列表.xlsx");
//            response.setCharacterEncoding("UTF-8");
//            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//            EasyExcel.write(response.getOutputStream(), ColdStorageComp.class).sheet("冷链企业列表").doWrite(coldStorageCompList);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }



}
